<?php
include("../fpdf/fpdf.php");
include("../db_connect.php");

class PDF extends FPDF
{
//include 
//setting the statements in loaddata()


	//$m_logo = "";
	//$m_logo = '../../images/mlogo.png';
	
	// Page header
	function Header()
	{
		$this->Image('../images/logo.png',70,5,70,20);
		// Arial bold 15
		$this->SetFont('Arial','B',15);
		// Move to the right
		$this->Cell(1);
		//set the text color
		
		// Title cell(x,y,title,border,?,?);
		$this->Cell(210,30,'Calumpit, Bulacan',0,0,'C');
		// Line break
		$this->Ln(20);	
		
		$this->SetFont('Arial','I',12);
		$this->Cell(60,25,'BasciAutoSales Manufacturer lists',0,0,'C');
		$this->Ln(20);	
	}

	// Page footer
	function Footer()
	{
		// Position at 1.5 cm from bottom
		$this->SetY(-15);
		// Arial italic 8
		$this->SetFont('Arial','',8);
		// Page number
		$this->Cell(0,10,'Page '.$this->PageNo().' Part List',0,0,'C');
		
	}
	
	function LoadData(){
		include("../db_connect.php");	
		
		$replace[] = ' ';
		$find[] = ',';
		$name = "";
		$address ="";
		$type = "";

		if(isset($_GET["name"])){
		$name = mysql_real_escape_string(htmlentities(trim($_GET["name"])));
		$$name = $name;
		}
		if(isset($_GET['address'])){
		$address = mysql_real_escape_string(htmlentities(trim($_GET["address"])));
		$address = $address;

		}
		if(isset($_GET['type'])){
		$type = mysql_real_escape_string(htmlentities(trim($_GET['type'])));
		$type = $type; 

		}
		$name = str_replace($find, $replace, $name);
		$sql = "SELECT * FROM tblmanufacturer WHERE manufacturename like '%".$name."%'";
		if($address != ""){
		$address = str_replace($find, $replace,$address);
		$sql .= " AND address like '%".$address."%' ";

		}
		if($type != ""){
		$type = str_replace($find, $replace, $_GET['type']);
			$sql .= " AND itemtype like '%".$type."%' ";
		}

		$sql .= " order by manufacturename ASC";
		
		$result = mysql_query($sql) or die(mysql_error());
		
		while($row=mysql_fetch_row($result)){ 
			$data[] = $row;
		}
		return $data;
		
		
	}


	//Colored table
	// Colored table
	function FancyTable($header, $data){
		
	//Colors, line width and bold font
			//Colors, line width and bold font
			$this->SetFillColor(70,70,70);
			$this->SetTextColor(255);
			$this->SetDrawColor(128,0,0);
			$this->SetLineWidth(.3);
			$this->SetFont('Arial','B',8);
			
			//Header
			$w=array(15,40,50,30);
			$type="";
			for($i=0;$i<count($header);$i++)
			$this->Cell($w[$i],4,$header[$i],1,0,'C',true);
			$this->Ln();
			//Color and font restoration
			$this->SetFillColor(225,235,255);
			$this->SetTextColor(0);
			$this->SetFont('Arial','B',8);
			//Data
			$fill=false;
			foreach($data as $row)
			{
				//$header=array('Txn id','Item Code','Qty','Total Pay','Name','Email','Date');
			
				$this->Cell($w[0],5,$row[0],'LR',0,'L',$fill);
				$this->Cell($w[1],5,$row[1],'LR',0,'L',$fill);
				$this->Cell($w[2],5,$row[2],'LR',0,'L',$fill);
				$this->Cell($w[3],5,$row[3],'LR',0,'L',$fill);
				
				$this->Ln();
				
				$fill=!$fill;
			}
			$this->Cell(array_sum($w),0,'','T');
		$this->Ln(10);
		
	}
	
	

}


$pdf=new PDF();


//Column titles
$header=array('Item Code','Name','Address','Type');
//Data loading
$data=$pdf->LoadData();

$pdf->AddPage();
$pdf->SetFont('Arial','',10);
// Move to the right
//$pdf->SetMargins(0.5, 0.5);
$pdf->Cell(1);

$pdf->Ln();
$pdf->FancyTable($header,$data);
$pdf->Output();

mysql_close($con);
?>